<!DOCTYPE html>

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>module RubyXL::OOXMLObjectClassMethods - rubyXL 3.4.35</title>


  <meta name="keywords" content="ruby,module,RubyXL::OOXMLObjectClassMethods">


    <meta name="description" content="Documentation for the RubyXL::OOXMLObjectClassMethods module">





<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
</script>

<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<link href="../css/fonts.css" rel="stylesheet">
<link href="../css/rdoc.css" rel="stylesheet">



<body id="top" role="document" class="module">
<div id="navigation-toggle" role="button" tabindex="0" aria-label="Toggle sidebar" aria-expanded="true" aria-controls="navigation">
  <span aria-hidden="true">&#9776;</span>
</div>


<nav id="navigation" role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="../index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  

  

  

  

  

  


  <div class="nav-section">
    <h3>Instance Methods</h3>
    <ul class="link-list" role="directory">

      <li ><a href="#method-i-define_attribute">define_attribute</a></li>

      <li ><a href="#method-i-define_child_node">define_child_node</a></li>

      <li ><a href="#method-i-define_element_name">define_element_name</a></li>

      <li ><a href="#method-i-define_relationship">define_relationship</a></li>

      <li ><a href="#method-i-obtain_class_variable">obtain_class_variable</a></li>

      <li ><a href="#method-i-parse">parse</a></li>

    </ul>
  </div>



  <footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a></p>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.15.1.</p>
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>
</footer>

</nav>

<main role="main" aria-labelledby="module-RubyXL::OOXMLObjectClassMethods">
  
  
    <ol role="navigation" aria-label="Breadcrumb navigation" class="breadcrumb">
      
      <li>
        
        <a href="../RubyXL.html">RubyXL</a><span>::</span>
        
      </li>
      
      <li>
        
        <span>OOXMLObjectClassMethods</span>
        
      </li>
      
    </ol>
  

  <h1 id="module-RubyXL::OOXMLObjectClassMethods" class="anchor-link module">
    module RubyXL::OOXMLObjectClassMethods
  </h1>

  <section class="description">
    
  </section>


  <section id="5Buntitled-5D" class="documentation-section anchor-link">









     <section id="public-instance-5Buntitled-5D-method-details" class="method-section anchor-link">
       <header>
         <h3>Public Instance Methods</h3>
       </header>


      <div id="method-i-define_attribute" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-define_attribute" title="Link to this method">
                <span class="method-name">define_attribute</span>
                <span class="method-args">(attr_name, attr_type, extra_params = nil)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="define_attribute-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 50</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">define_attribute</span>(<span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">attr_type</span>, <span class="ruby-identifier">extra_params</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">attrs</span> = <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-value">:@@ooxml_attributes</span>)
  <span class="ruby-identifier">attr_hash</span> = { <span class="ruby-value">:attr_type</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">attr_type</span> }
  <span class="ruby-identifier">attr_hash</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">extra_params</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">extra_params</span>
  <span class="ruby-identifier">attr_hash</span>[<span class="ruby-value">:accessor</span>] <span class="ruby-operator">||=</span> <span class="ruby-identifier">accessorize</span>(<span class="ruby-identifier">attr_name</span>)
  <span class="ruby-identifier">attrs</span>[<span class="ruby-identifier">attr_name</span>.<span class="ruby-identifier">to_s</span>] = <span class="ruby-identifier">attr_hash</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:attr_accessor</span>, <span class="ruby-identifier">attr_hash</span>[<span class="ruby-value">:accessor</span>]) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">attr_hash</span>[<span class="ruby-value">:computed</span>]
<span class="ruby-keyword">end</span></pre>
          </div>



          <p>Defines an attribute of OOXML object.</p>

<h3 id="method-i-define_attribute-label-Parameters">Parameters<span><a href="#method-i-define_attribute-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><code>attribute_name</code> - Name of the element attribute as seen in the source XML. Can be either <code>&quot;String&quot;</code> or <code>:Symbol</code></p>
<ul><li>
<p>Special attribute name <code>&#39;_&#39;</code> (underscore) denotes the value of the element rather than attribute.</p>
</li></ul>
</li><li>
<p><code>attribute_type</code> - Specifies the conversion type for the attribute when parsing. Available options are:</p>
<ul><li>
<p><code>:int</code> - <code>Integer</code></p>
</li><li>
<p><code>:uint</code> - Unsigned <code>Integer</code></p>
</li><li>
<p><code>:double</code> - <code>Float</code>&lt;/u&gt;</p>
</li><li>
<p><code>:string</code> - <code>String</code> (no conversion)</p>
</li><li>
<p><code>:sqref</code> - <a href="Sqref.html"><code>RubyXL::Sqref</code></a></p>
</li><li>
<p><code>:ref</code> - <a href="Reference.html"><code>RubyXL::Reference</code></a></p>
</li><li>
<p><code>:bool</code> - <code>Boolean</code> (“1” and “true” convert to <code>true</code>, others to <code>false</code>)</p>
</li><li>
<p>one of <a href="../lib/rubyXL/objects/simple_types_rb.html">simple_types</a> - <code>String</code>, plus the list of acceptable values is saved for future validation (not used yet).</p>
</li></ul>
</li><li>
<p><code>extra_parameters</code> - Hash of optional parameters as follows:</p>
<ul><li>
<p><code>:accessor</code> - Name of the accessor for this attribute to be defined on the object. If not provided, defaults to classidied <code>attribute_name</code>.</p>
</li><li>
<p><code>:default</code> - Value this attribute defaults to if not explicitly provided.</p>
</li><li>
<p><code>:required</code> - Whether this attribute is required when writing XML. If the value of the attrinute is not explicitly provided, <code>:default</code> is written instead.</p>
</li><li>
<p><code>:computed</code> - Do not store this attribute on <code>parse</code>, but do call the object-provided read accessor on <code>write_xml</code>.</p>
</li></ul>
</li></ul>

<h4 id="method-i-define_attribute-label-Examples">Examples<span><a href="#method-i-define_attribute-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">define_attribute</span>(<span class="ruby-value">:outline</span>, <span class="ruby-value">:bool</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-keyword">true</span>)
</pre>

<p>A <code>Boolean</code> attribute ‘outline’ with default value <code>true</code> will be accessible by calling <code>obj.outline</code></p>

<pre class="ruby"><span class="ruby-identifier">define_attribute</span>(<span class="ruby-value">:uniqueCount</span>,  <span class="ruby-value">:int</span>)
</pre>

<p>An <code>Integer</code> attribute ‘uniqueCount’ accessible as <code>obj.unique_count</code></p>

<pre class="ruby"><span class="ruby-identifier">define_attribute</span>(<span class="ruby-value">:_</span>,  <span class="ruby-value">:string</span>, <span class="ruby-value">:accessor</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:expression</span>)
</pre>

<p>The value of the element will be accessible as a <code>String</code> by calling <code>obj.expression</code></p>

<pre class="ruby"><span class="ruby-identifier">define_attribute</span>(<span class="ruby-value">:errorStyle</span>, <span class="ruby-node">%w{ stop warning information }</span>, <span class="ruby-value">:default</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&#39;stop&#39;</span>,)
</pre>

<p>A <code>String</code> attribute named ‘errorStyle’ will be accessible as <code>obj.error_style</code>, valid values are <code>&quot;stop&quot;</code>, <code>&quot;warning&quot;</code>, <code>&quot;information&quot;</code></p>


        </div>





      </div>


      <div id="method-i-define_child_node" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-define_child_node" title="Link to this method">
                <span class="method-name">define_child_node</span>
                <span class="method-args">(klass, extra_params = {})</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="define_child_node-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 84</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">define_child_node</span>(<span class="ruby-identifier">klass</span>, <span class="ruby-identifier">extra_params</span> = {})
  <span class="ruby-identifier">child_nodes</span> = <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-value">:@@ooxml_child_nodes</span>)
  <span class="ruby-identifier">child_node_name</span> = (<span class="ruby-identifier">extra_params</span>[<span class="ruby-value">:node_name</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">class_variable_get</span>(<span class="ruby-value">:@@ooxml_tag_name</span>)).<span class="ruby-identifier">to_s</span>
  <span class="ruby-identifier">accessor</span> = (<span class="ruby-identifier">extra_params</span>[<span class="ruby-value">:accessor</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">accessorize</span>(<span class="ruby-identifier">child_node_name</span>)).<span class="ruby-identifier">to_sym</span>

  <span class="ruby-identifier">child_nodes</span>[<span class="ruby-identifier">child_node_name</span>] = {
    <span class="ruby-value">:class</span>    <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">klass</span>,
    <span class="ruby-value">:is_array</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">extra_params</span>[<span class="ruby-value">:collection</span>],
    <span class="ruby-value">:accessor</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">accessor</span>
  }

  <span class="ruby-identifier">define_count_attribute</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">extra_params</span>[<span class="ruby-value">:collection</span>] <span class="ruby-operator">==</span> <span class="ruby-value">:with_count</span>

  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-value">:attr_accessor</span>, <span class="ruby-identifier">accessor</span>)
<span class="ruby-keyword">end</span></pre>
          </div>



          <p>Defines a child node of OOXML object.</p>

<h3 id="method-i-define_child_node-label-Parameters">Parameters<span><a href="#method-i-define_child_node-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><code>klass</code> - Class (descendant of <a href="OOXMLObject.html"><code>RubyXL::OOXMLObject</code></a>) of the child nodes. Child node objects will be produced by calling <code>parse</code> method of that class.</p>
</li><li>
<p><code>extra_parameters</code> - Hash of optional parameters as follows:</p>
<ul><li>
<p><code>:accessor</code> - Name of the accessor for this attribute to be defined on the object. If not provided, defaults to classidied <code>attribute_name</code>.</p>
</li><li>
<p><code>:node_name</code> - Node name for the child node, in case it does not match the one defined by the <code>klass</code>.</p>
</li><li>
<p><code>:collection</code> - Whether the child node should be treated as a single node or a collection of nodes:</p>
<ul><li>
<p><code>false</code> (default) - child node is directly accessible through the respective accessor;</p>
</li><li>
<p><code>true</code> - a collection of child nodes is accessed as <code>Array</code> through the respective accessor;</p>
</li><li>
<p><code>:with_count</code> - same as <code>true</code>, but in addition, the attribute <code>count</code> is defined on the current object, that will be automatically set to the number of elements in the collection at the start of <code>write_xml</code> call.</p>
</li></ul>
</li></ul>
</li></ul>

<h4 id="method-i-define_child_node-label-Examples">Examples<span><a href="#method-i-define_child_node-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">define_child_node</span>(<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Alignment</span>)
</pre>

<p>Define a singular child node parsed by the RubyXL::BorderEdge.parse() and accessed by the default <code>obj.alignment</code> accessor</p>

<pre class="ruby"><span class="ruby-identifier">define_child_node</span>(<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Hyperlink</span>, <span class="ruby-value">:collection</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-keyword">true</span>, <span class="ruby-value">:accessor</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:hyperlinks</span>)
</pre>

<p>Define an array of nodes accessed by <code>obj.hyperlinks</code> accessor, each of which will be parsed by the RubyXL::Hyperlink.parse()</p>

<pre class="ruby"><span class="ruby-identifier">define_child_node</span>(<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">BorderEdge</span>, <span class="ruby-value">:node_name</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:left</span>)
<span class="ruby-identifier">define_child_node</span>(<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">BorderEdge</span>, <span class="ruby-value">:node_name</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:right</span>)
</pre>

<p>Use class <a href="BorderEdge.html"><code>RubyXL::BorderEdge</code></a> when parsing both the elements <code>&lt;left ...&gt;</code> and <code>&lt;right ...&gt;</code> elements.</p>

<pre class="ruby"><span class="ruby-identifier">define_child_node</span>(<span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">Font</span>, <span class="ruby-value">:collection</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:with_count</span>, <span class="ruby-value">:accessor</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">:fonts</span>)
</pre>

<p>Upon writing of the object this was defined on, its <code>count</code> attribute will be set to the count of nodes in <code>fonts</code> array</p>


        </div>





      </div>


      <div id="method-i-define_element_name" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-define_element_name" title="Link to this method">
                <span class="method-name">define_element_name</span>
                <span class="method-args">(element_name)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="define_element_name-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 112</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">define_element_name</span>(<span class="ruby-identifier">element_name</span>)
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class_variable_set</span>(<span class="ruby-value">:@@ooxml_tag_name</span>, <span class="ruby-identifier">element_name</span>)
<span class="ruby-keyword">end</span></pre>
          </div>



          <p>Defines the name of the element that represents the current OOXML object. Should only be used once per object. In case of different objects represented by the same class in different parts of OOXML tree, <code>:node_name</code> extra parameter can be used to override the default element name.</p>

<h3 id="method-i-define_element_name-label-Parameters">Parameters<span><a href="#method-i-define_element_name-label-Parameters">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><code>element_name</code></p>
</li></ul>

<h4 id="method-i-define_element_name-label-Examples">Examples<span><a href="#method-i-define_element_name-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">define_element_name</span> <span class="ruby-string">&#39;externalReference&#39;</span>
</pre>


        </div>





      </div>


      <div id="method-i-define_relationship" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-define_relationship" title="Link to this method">
                <span class="method-name">define_relationship</span>
                <span class="method-args">(extra_params = {})</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="define_relationship-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">define_relationship</span>(<span class="ruby-identifier">extra_params</span> = {})
  <span class="ruby-identifier">define_attribute</span>(<span class="ruby-value">:&#39;r:id&#39;</span>, <span class="ruby-value">:string</span>, <span class="ruby-identifier">extra_params</span>)
<span class="ruby-keyword">end</span></pre>
          </div>



          <p>Defines a ‘r:id` attribute</p>


        </div>





      </div>


      <div id="method-i-obtain_class_variable" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-obtain_class_variable" title="Link to this method">
                <span class="method-name">obtain_class_variable</span>
                <span class="method-args">(var_name, default = nil)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="obtain_class_variable-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 15</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">obtain_class_variable</span>(<span class="ruby-identifier">var_name</span>, <span class="ruby-identifier">default</span> = <span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class_variable_defined?</span> <span class="ruby-identifier">var_name</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class_variable_get</span>(<span class="ruby-identifier">var_name</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class_variable_set</span>(<span class="ruby-identifier">var_name</span>, <span class="ruby-identifier">default</span> <span class="ruby-operator">||</span> {})
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>



          <p>Get the value of a [sub]class variable if it exists, or create the respective variable with the passed-in <code>default</code> (or +{}+, if not specified)</p>

<p>Throughout this class, we are setting class variables through explicit method calls rather than by directly addressing the name of the variable because of context issues: addressing variable by name creates it in the context of defining class, while calling the setter/getter method addresses it in the context of descendant class, which is what we need.</p>


        </div>





      </div>


      <div id="method-i-parse" class="method-detail anchor-link ">
        <div class="method-header">

            <div class="method-heading">
              <a href="#method-i-parse" title="Link to this method">
                <span class="method-name">parse</span>
                <span class="method-args">(node, known_namespaces = nil)</span>
              </a>
            </div>

        </div>


          <div class="method-controls">
            <details class="method-source-toggle">
              <summary>Source</summary>
            </details>
          </div>



        <div class="method-description">

          <div class="method-source-code" id="parse-source">
            <pre><span class="ruby-comment"># File lib/rubyXL/objects/ooxml_object.rb, line 116</span>
    <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">parse</span>(<span class="ruby-identifier">node</span>, <span class="ruby-identifier">known_namespaces</span> = <span class="ruby-keyword">nil</span>)
      <span class="ruby-keyword">case</span> <span class="ruby-identifier">node</span>
      <span class="ruby-keyword">when</span> <span class="ruby-constant">String</span>, <span class="ruby-constant">IO</span>, <span class="ruby-constant">Zip</span><span class="ruby-operator">::</span><span class="ruby-constant">InputStream</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">node</span> = <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">node</span>)
      <span class="ruby-keyword">end</span>

      <span class="ruby-keyword">if</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>) <span class="ruby-keyword">then</span>
        <span class="ruby-identifier">node</span> = <span class="ruby-identifier">node</span>.<span class="ruby-identifier">root</span>
<span class="ruby-comment">#        ignorable_attr = node.attributes[&#39;Ignorable&#39;]</span>
<span class="ruby-comment">#        @ignorables &lt;&lt; ignorable_attr.value if ignorable_attr</span>
      <span class="ruby-keyword">end</span>

      <span class="ruby-identifier">obj</span> = <span class="ruby-keyword">self</span>.<span class="ruby-identifier">new</span>
      <span class="ruby-identifier">hsh</span> = {}
      <span class="ruby-identifier">node</span>.<span class="ruby-identifier">namespace_definitions</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">ns</span><span class="ruby-operator">|</span> <span class="ruby-identifier">hsh</span>[<span class="ruby-identifier">ns</span>.<span class="ruby-identifier">href</span>] = <span class="ruby-identifier">ns</span>.<span class="ruby-identifier">prefix</span> }
      <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">local_namespaces</span> = <span class="ruby-identifier">hsh</span>

      <span class="ruby-identifier">known_attributes</span> = <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-value">:@@ooxml_attributes</span>)

      <span class="ruby-identifier">content_params</span> = <span class="ruby-identifier">known_attributes</span>[<span class="ruby-string">&#39;_&#39;</span>]
      <span class="ruby-identifier">process_attribute</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">node</span>.<span class="ruby-identifier">text</span>, <span class="ruby-identifier">content_params</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">content_params</span>

      <span class="ruby-identifier">node</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">attr_name</span>, <span class="ruby-identifier">attr</span><span class="ruby-operator">|</span>
        <span class="ruby-identifier">attr_name</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">namespace</span> <span class="ruby-keyword">then</span> <span class="ruby-node">&quot;#{attr.namespace.prefix}:#{attr.name}&quot;</span>
                    <span class="ruby-keyword">else</span> <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">name</span>
                    <span class="ruby-keyword">end</span>

        <span class="ruby-identifier">attr_params</span> = <span class="ruby-identifier">known_attributes</span>[<span class="ruby-identifier">attr_name</span>]

        <span class="ruby-keyword">next</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">attr_params</span>.<span class="ruby-identifier">nil?</span>
        <span class="ruby-comment"># raise &quot;Unknown attribute [#{attr_name}] for element [#{node.name}]&quot; if attr_params.nil?</span>
        <span class="ruby-identifier">process_attribute</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">value</span>, <span class="ruby-identifier">attr_params</span>) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">attr_params</span>[<span class="ruby-value">:computed</span>]
      }

      <span class="ruby-identifier">known_child_nodes</span> = <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-value">:@@ooxml_child_nodes</span>)

      <span class="ruby-keyword">unless</span> <span class="ruby-identifier">known_child_nodes</span>.<span class="ruby-identifier">empty?</span>
        <span class="ruby-identifier">known_namespaces</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">obtain_class_variable</span>(<span class="ruby-value">:@@ooxml_namespaces</span>)

        <span class="ruby-identifier">node</span>.<span class="ruby-identifier">element_children</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">child_node</span><span class="ruby-operator">|</span>
          <span class="ruby-identifier">ns</span> = <span class="ruby-identifier">child_node</span>.<span class="ruby-identifier">namespace</span>

          <span class="ruby-identifier">prefix</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">known_namespaces</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">ns</span>&amp;.<span class="ruby-identifier">href</span>) <span class="ruby-keyword">then</span> <span class="ruby-identifier">known_namespaces</span>[<span class="ruby-identifier">ns</span>&amp;.<span class="ruby-identifier">href</span>]
                   <span class="ruby-keyword">else</span> <span class="ruby-identifier">ns</span>&amp;.<span class="ruby-identifier">prefix</span>
                   <span class="ruby-keyword">end</span>

          <span class="ruby-identifier">child_node_name</span> = <span class="ruby-keyword">case</span> <span class="ruby-identifier">prefix</span>
                            <span class="ruby-keyword">when</span> <span class="ruby-string">&#39;&#39;</span>, <span class="ruby-keyword">nil</span> <span class="ruby-keyword">then</span> <span class="ruby-identifier">child_node</span>.<span class="ruby-identifier">name</span>
                            <span class="ruby-keyword">else</span> <span class="ruby-node">&quot;#{prefix}:#{child_node.name}&quot;</span>
                            <span class="ruby-keyword">end</span>

          <span class="ruby-identifier">child_node_params</span> = <span class="ruby-identifier">known_child_nodes</span>[<span class="ruby-identifier">child_node_name</span>]
          <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Unknown child node [#{child_node_name}] for element [#{node.name}]&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">child_node_params</span>.<span class="ruby-identifier">nil?</span>
          <span class="ruby-identifier">parsed_object</span> = <span class="ruby-identifier">child_node_params</span>[<span class="ruby-value">:class</span>].<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">child_node</span>, <span class="ruby-identifier">known_namespaces</span>)
          <span class="ruby-keyword">if</span> <span class="ruby-identifier">child_node_params</span>[<span class="ruby-value">:is_array</span>] <span class="ruby-keyword">then</span>
            <span class="ruby-identifier">index</span> = <span class="ruby-identifier">parsed_object</span>.<span class="ruby-identifier">index_in_collection</span>

            <span class="ruby-identifier">collection</span> = <span class="ruby-keyword">if</span> (<span class="ruby-keyword">self</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">RubyXL</span><span class="ruby-operator">::</span><span class="ruby-constant">OOXMLContainerObject</span>) <span class="ruby-keyword">then</span> <span class="ruby-identifier">obj</span>
                         <span class="ruby-keyword">else</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">child_node_params</span>[<span class="ruby-value">:accessor</span>])
                         <span class="ruby-keyword">end</span>

            <span class="ruby-keyword">if</span> <span class="ruby-identifier">index</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword">then</span>
              <span class="ruby-identifier">collection</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">parsed_object</span>
            <span class="ruby-keyword">else</span>
              <span class="ruby-identifier">collection</span>[<span class="ruby-identifier">index</span>] = <span class="ruby-identifier">parsed_object</span>
            <span class="ruby-keyword">end</span>
          <span class="ruby-keyword">else</span>
            <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">&quot;#{child_node_params[:accessor]}=&quot;</span>, <span class="ruby-identifier">parsed_object</span>)
          <span class="ruby-keyword">end</span>
        }
      <span class="ruby-keyword">end</span>

      <span class="ruby-identifier">obj</span>
    <span class="ruby-keyword">end</span></pre>
          </div>



          


        </div>





      </div>


    </section>

  </section>

</main>
</body>

